package com.zzyl.exception;

import com.zzyl.base.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 处理基本异常
     * @param ex
     * @return
     */
    @ExceptionHandler(BaseException.class)
    public ResponseResult<String> handlerBaseException(BaseException ex){
        ex.printStackTrace();
        return ResponseResult.error(ex.getBasicEnum());
    }

    /**
     * 处理运行时异常
     * @param ex
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public ResponseResult<String> handlerRuntimeException(RuntimeException ex){
        ex.printStackTrace();
        return ResponseResult.error(ex.getMessage());
    }

    /**
     * 处理未知异常
     * @param ex
     * @return
     */
    @ExceptionHandler(Exception.class)
    public ResponseResult<String> handlerUnKnowException(Exception ex){
        ex.printStackTrace();
        return ResponseResult.error(ex.getMessage());
    }


}
